package com.example.tests;
import org.testng.annotations.Test;
// import static org.testng.Assert.*;
import java.util.logging.Logger;

import org.testng.annotations.AfterMethod;

import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;

import com.example.fw.GroupObject;
import com.example.fw.Groups;

public class GroupCreationTests extends TestBase{

	private Logger log = Logger.getLogger("GroupCreationTests");
	

	
	@Test(dataProvider = "groupsFromFile", dataProviderClass = GroupDataGenerator.class) 
	public void testValidGroupCanBeCreated(GroupObject validGroup) throws Exception {
//		log.info("testValidGroupCanBeCreated start");
		Groups oldList = app.getGroupHelper().getGroups();
//		log.info("oldList =" + oldList);
		app.getGroupHelper().createGroup(validGroup);
//		log.info("validGroup =" + validGroup);
		Groups newList = app.getGroupHelper().getGroups();
//		log.info("newList =" + newList);
		assertThat(newList, equalTo(oldList.withAdded(validGroup)));
//		log.info("testValidGroupCanBeCreated end");
	}
		
	@Test
	public void testGroupWithEmptyDataCanBeCreated() throws Exception {
		Groups oldList = app.getHibernateHelper().getGroups();
		GroupObject validGroup = new GroupObject()
		.setName("").setHeader("").setFooter("");
		app.getGroupHelper().createGroup(validGroup);
		Groups newList = app.getHibernateHelper().getGroups();
//		verifyGroupAdded(oldList, validGroup, newList);
		assertThat(newList, equalTo(oldList.withAdded(validGroup)));
	}
	
//	@AfterMethod 
	public void testUiAndDbConfirmsWithModel(){
		if(app.getProperty("ui.check") != null){
		Groups modelList = app.getGroupHelper().getGroups();
		Groups uiList = app.getGroupHelper().getUiGroups();
		assertThat(uiList, equalTo(modelList));
		
	}
		if(app.getProperty("db.check") != null){
		Groups modelList = app.getGroupHelper().getGroups();
		Groups dbList = app.getHibernateHelper().getGroups();
		assertThat(dbList, equalTo(modelList));
		
	}
	
	
}
}